


def searchDefinition(text):
    search = "\'"
    start = text.find(search)
    print start
    isTrue = True
    i = 0
    while(isTrue):
        start = text.find(dSearch[0],i) 
        finish = text.find(dSearch[1],i) 
        if start >=0:
            for i in stopWord.split():
                if text[start:finish].find(i) >=0:       
                    isTrue = False
        else:
            return False
        i = finish + 1
    print text[start:finish+8]   
    return searchInTable(text[start:finish+8])


def discoveryMonthlyUptime(text):
    
    search = "<table </table>"
    stopWord = "Monthly Uptime Availability"
    dSearch = search.split()
    isTrue = True
    i = 0
    while(isTrue):
        start = text.find(dSearch[0],i) 
        finish = text.find(dSearch[1],i) 
        if start >=0:
            for i in stopWord.split():
                if text[start:finish].find(i) >=0:       
                    isTrue = False
        else:
            return False
        i = finish + 1
    print text[start:finish+8]   
    return searchInTable(text[start:finish+8])
    
def searchInTable(text):
    search = "<td </td>"
    dSearch = search.split()
    dicc = {}
    for i in range(2):
        start = text.find(dSearch[0])
        count = start +1
        while(text[count]!='>'):
            text = text.replace(text[count],"",1)
        text = text.replace(text[count]," ",1)
        finish = text.find(dSearch[1])
        collumn = text[(count+1):finish]
        text = text[finish+5:]
        dicc.update({collumn:[]})
    start = text.find(dSearch[0])

    while(start>=0):
        count = start +1
        while(text[count]!='>'):
            text = text.replace(text[count],"",1)
        text = text.replace(text[count]," ",1)
        finish = text.find(dSearch[1])
        value = text[(count+1):finish]
        print value
        text = text[finish+5:]
        dicc[dicc.keys()[0]].append(value)
        
        start = text.find(dSearch[0])
        count = start +1
        while(text[count]!='>'):
            text = text.replace(text[count],"",1)
        text = text.replace(text[count]," ",1)
        finish = text.find(dSearch[1])
        value = text[(count+1):finish]
        text = text[finish+5:]
        dicc[dicc.keys()[1]].append(value)
        
        start = text.find(dSearch[0])
    return dicc
    
    
    

if __name__ == '__main__':
    text= """
    1.  DEFINED TERMS.  The following words used in this Customer Agreement have the following meanings:
'Acceptable Use Policy' or 'AUP' means HP's Acceptable Use Policy, as HP may amend from time to time. 
 """
    print text
    searchDefinition(text)